home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / MiniGames / BaseMiniGame.as
Encoding:
Text File  |  2013-04-24  |  4.5 KB  |  166 lines

  1. class MiniGames.BaseMiniGame extends State
  2. {
  3.    var bOver;
  4.    var nTime;
  5.    var mcRef;
  6.    var sState;
  7.    var oListener;
  8.    static var sSTATE_HOWTOPLAY_IN = "HowToPlayIn";
  9.    static var sSTATE_HOWTOPLAY_IDLE = "HowToPlayIdle";
  10.    static var sSTATE_HOWTOPLAY_OUT = "HowToPlayOut";
  11.    static var sSTATE_MINIGAME = "MiniGame";
  12.    static var sSTATE_VICTORY = "Victory";
  13.    static var nSCORE_MAX = 1200;
  14.    static var nWAITING_TIME = 105;
  15.    function BaseMiniGame(_mcRef)
  16.    {
  17.       super(_mcRef);
  18.       this.bOver = false;
  19.    }
  20.    function initMiniGame()
  21.    {
  22.    }
  23.    function validateEndMiniGame()
  24.    {
  25.    }
  26.    function destroyMiniGame(_bQuitting)
  27.    {
  28.       if(_bQuitting == false || _bQuitting == undefined)
  29.       {
  30.          this.calculateScore();
  31.       }
  32.       this.cleanUp();
  33.    }
  34.    function calculateScore()
  35.    {
  36.    }
  37.    function addScoreFromTimeLeft(_nTimeMax, _nSecondsValue)
  38.    {
  39.       var _loc4_ = Math.round(_nTimeMax - this.nTime / Main.nFRAME_RATE);
  40.       if(_loc4_ < 0)
  41.       {
  42.          _loc4_ = 0;
  43.       }
  44.       _loc4_ *= _nSecondsValue;
  45.       if(_loc4_ > MiniGames.BaseMiniGame.nSCORE_MAX)
  46.       {
  47.          _loc4_ = MiniGames.BaseMiniGame.nSCORE_MAX;
  48.       }
  49.       CTRLGame.getRef().addToScore(_loc4_);
  50.    }
  51.    function isFinished()
  52.    {
  53.       return this.bOver;
  54.    }
  55.    function showInstructions()
  56.    {
  57.       this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IN);
  58.       Controller.getRef().getSounds().playSound("Minigame_HowToPlay_In",Controller.nSFX_VOLUME,1);
  59.    }
  60.    function doPause()
  61.    {
  62.       super.doPause();
  63.    }
  64.    function doUnPause()
  65.    {
  66.       super.doUnPause();
  67.       this.mcRef.stop();
  68.    }
  69.    function startGame()
  70.    {
  71.       this.clearSkipKeys();
  72.       this.setState(MiniGames.BaseMiniGame.sSTATE_MINIGAME);
  73.       CTRLGame.getRef().Screen.getInterface().unPauseTime();
  74.       this.initMiniGame();
  75.       this.nTime = 0;
  76.    }
  77.    function setVictory()
  78.    {
  79.       this.setState(MiniGames.BaseMiniGame.sSTATE_VICTORY);
  80.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  81.    }
  82.    function pressKey()
  83.    {
  84.       if(Key.getCode() != Key.UP && (Key.getCode() != Key.DOWN && (Key.getCode() != Key.LEFT && (Key.getCode() != Key.RIGHT && this.sState == MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE))))
  85.       {
  86.          this.skipInstructions();
  87.       }
  88.    }
  89.    function pressMouseButton()
  90.    {
  91.       Controller.getRef().playClickSound();
  92.       this.skipInstructions();
  93.    }
  94.    function skipInstructions()
  95.    {
  96.       this.clearSkipKeys();
  97.       this.onOutInstructions();
  98.    }
  99.    function onOutInstructions()
  100.    {
  101.       this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_OUT);
  102.       Controller.getRef().getSounds().playSound("Minigame_HowToPlay_Out",Controller.nSFX_VOLUME,1);
  103.    }
  104.    function clearSkipKeys()
  105.    {
  106.       delete this.mcRef.mcState.btnSkip.onRelease;
  107.       delete this.mcRef.mcState.btnSkip2.onRelease;
  108.       delete this.mcRef.mcState.btnSkip2.onRollOver;
  109.       this.mcRef.mcState.btnSkip.onRelease = undefined;
  110.       this.mcRef.mcState.btnSkip2.onRelease = undefined;
  111.       this.mcRef.mcState.btnSkip2.onRollOver = undefined;
  112.       if(this.oListener != null)
  113.       {
  114.          Key.removeListener(this.oListener);
  115.          delete this.oListener;
  116.          this.oListener = null;
  117.       }
  118.    }
  119.    function initSkipKeys()
  120.    {
  121.       this.oListener = new Object();
  122.       this.oListener.onKeyDown = Delegate.create(this,this.pressKey);
  123.       Key.addListener(this.oListener);
  124.       this.mcRef.mcState.btnSkip.onRelease = Delegate.create(this,this.skipInstructions);
  125.       this.mcRef.mcState.btnSkip2.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  126.       this.mcRef.mcState.btnSkip2.onRelease = Delegate.create(this,this.pressMouseButton);
  127.    }
  128.    function HowToPlayIn()
  129.    {
  130.       if(this.stateFinished())
  131.       {
  132.          this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE);
  133.          this.initSkipKeys();
  134.       }
  135.    }
  136.    function HowToPlayIdle()
  137.    {
  138.       if(this.stateFinished())
  139.       {
  140.          this.onOutInstructions();
  141.       }
  142.    }
  143.    function HowToPlayOut()
  144.    {
  145.       if(this.stateFinished())
  146.       {
  147.          this.startGame();
  148.       }
  149.    }
  150.    function MiniGame()
  151.    {
  152.       if(!Controller.getRef().isPaused())
  153.       {
  154.          this.nTime = this.nTime + 1;
  155.          this.validateEndMiniGame();
  156.       }
  157.    }
  158.    function Victory()
  159.    {
  160.       if(this.stateFinished())
  161.       {
  162.          this.bOver = true;
  163.       }
  164.    }
  165. }
  166.